<%@ page import="dart.Person" %>
<%@ page import="dart.PlayerGame" %>
<% people = Person.findAllByEnabled(true)

wins = [:]
ties = [:]
losses = [:]
people.each {Person person ->
	wins[person] = 0;
	ties[person] = 0;
	losses[person] = 0;
	List playerGames = PlayerGame.findAllByPerson(person)

	playerGames.each {PlayerGame playerGame ->
		switch (playerGame.status) {
			case PlayerGame.WON:
				wins[person] = wins[person] + 1;
				break;
			case PlayerGame.TIE:
				ties[person] = ties[person] + 1;
				break;
			case PlayerGame.LOST:
				losses[person] = losses[person] + 1;
				break;
			case PlayerGame.IN_PROGRESS:
				break;
			default:
				println("Status of ${playerGame.status} with id ${playerGame.id}")
		}
	}
}
%>

<table id="scores" cellspacing="0">
	<thead>
	<tr>
		<th width="52%">Player</th>
		<th width="16%">Wins</th>
		<th width="16%">Ties</th>
		<th width="16%">Losses</th>
	</tr>
	</thead>

	<tbody>
	<g:each in="${people}" var="person" status="sts">
		<tr class="${sts % 2 ? "odd" : "even"}">
			<td class="person">${person.displayName}</td>
			<td>${wins[person]}</td>
			<td>${ties[person]}</td>
			<td>${losses[person]}</td>
		</tr>
	</g:each>
	</tbody>
</table>